
import { getStrByBytesLen, getStrBytesLen } from '@/libs/tools'
export default {
    computed: {
        // 运费是否必填
        // 出口 CIF C&F;进口 FOB C&I
        feeMarkRequired () {
            const { transMode, ieFlag } = this.form
            let list = ieFlag == 'E' ? ['1', '2'] : ['3', '4']
            return list.includes(transMode)
        },
        // 运费是否不可填写
        // 进口 CIF C&F;出口 FOB C&I
        feeDisabled () {
            const { transMode, ieFlag } = this.form
            let list = ieFlag == 'I' ? ['1', '2'] : ['3', '4']
            return list.includes(transMode)
        },
        // 保险费是否必填
        // 出口 CIF C&I;进口 FOB C&F
        insurMarkRequird () {
            const { transMode, ieFlag } = this.form
            let list = ieFlag == 'E' ? ['1', '4'] : ['3', '2']
            return list.includes(transMode)
        },
        // 保险费是否不可填写
        // 进口 CIF C&F;出口 FOB C&I
        insurDisabled () {
            const { transMode, ieFlag } = this.form
            let list = ieFlag == 'I' ? ['1', '4'] : ['3', '2']
            return list.includes(transMode)
        },
        // 备注字节长度
        notesLen () {
            const { notes } = this.form
            return getStrBytesLen(notes || '')
        },
        // 标记唛码字节长度
        markNoLen () {
            const { markNo } = this.form
            return getStrBytesLen(markNo || '')
        }
    },
    watch: {
        'form.transMode' (newVal) {
            if (this.feeDisabled) {
                this.form.feeMark = ''
                this.form.feeRate = ''
                this.form.feeCurr = ''
                this.validateField('feeRate')
                this.validateField('feeMark')
            }
            if (this.insurDisabled) {
                this.form.insurMark = ''
                this.form.insurRate = ''
                this.form.insurCurr = ''
                this.validateField('insurMark')
                this.validateField('insurRate')
            }
            if (!newVal) {
                this.validateField('feeMark')
                this.validateField('insurMark')
            }
        }
    },
    methods: {
        // 格式化备注
        fmtNotes () {
            if (this.notesLen > 255) {
                this.form.notes = getStrByBytesLen(
                    this.form.notes,
                    255
                )
            }
        },
        // 格式化标记唛码
        fmtMarkNo () {
            if (this.markNoLen > 400) {
                this.form.markNo = getStrByBytesLen(
                    this.form.markNo,
                    400
                )
            }
        }
    }
}
